class GamesController < ActionController::Base
	def new 
		puts "------------------------------------------GAMES#NEW--------------------------------------"
		@game = Game.new
		@game.players.build
	end
	def index
		puts "------------------------------------------GAMES#INDEX--------------------------------------"
		session[:player_id] = nil
		@games = Game.find :all
	end
	def create
		puts "------------------------------------------GAMES#CREATE--------------------------------------"
		@game = Game.create params[:game]
		@player_id = @game.players[0].id
		redirect_to play_path(@game.id, @player_id)
	end
	def show
		puts "------------------------------------------GAMES#SHOW--------------------------------------"
		@game = Game.find params[:id]
		if @game.contract_final
			@contract_player_name = (Player.find @game.contract_player).name
		end
		@player_id = params[:player_id]
		unless session[:player_id].nil? || session[:player_id].to_s == @player_id.to_s
			redirect_to games_path
		end
		@north = @game.north
		@south = @game.south
		@east = @game.east
		@west = @game.west
	end
	def edit
		puts "------------------------------------------GAMES#EDIT--------------------------------------"
		@game = Game.find params[:id]
		@game.players.build
	end
	def update
		puts "------------------------------------------GAMES#UPDATE--------------------------------------"
		@game = Game.find params[:id]
		@game.update_attributes(params[:game])
	end
	def deal
		puts "------------------------------------------GAMES#DEAL--------------------------------------"
		@game = Game.find params[:id]
		@game.deal
		if params[:player_id].nil?
			redirect_to game_path @game.id		
		else
			redirect_to play_path @game.id, params[:player_id]
		end
	end
	def login
		puts "------------------------------------------GAMES#LOGIN--------------------------------------"
		@player = Player.find params[:player_id]
		@game = Game.find params[:id]
	end
	def bid
		puts "------------------------------------------GAMES#BID--------------------------------------"
		@game = Game.find params[:id]
		@game.bid params[:player_id], params[:value].to_i, params[:suit]
		redirect_to play_path params[:id], params[:player_id]
	end
	def play_card
		puts "------------------------------------------GAMES#PLAY_CARD--------------------------------------"
		@game = Game.find params[:id]
		@game.play_card(params[:player_id], params[:card_id]

		redirect_to play_path params[:id], params[:player_id]
	end
end
